library(jpeg)
img <- readJPEG("C:/Users/ilker zeybek/Desktop/423part1.jpg", native = FALSE)
plot(NA,xlim=c(0,nrow(img)),ylim=c(0,ncol(img)))
rasterImage(img,0,0,nrow(img),ncol(img))
We have created objects called “a”,“b”, and “c” for storing the first, second, and the third channels of our image, respectively. Then plotted channels using rasterImage() function and showed them in a single plot.
a <- img[,,1]
b <- img[,,2]
c <- img[,,3]
par(mfrow=c(1,3))
plot(NA,xlim=c(0,nrow(a)),ylim=c(0,ncol(a)))
rasterImage(a,0,0,nrow(a),ncol(a))
plot(NA,xlim=c(0,nrow(b)),ylim=c(0,ncol(b)))
rasterImage(b,0,0,nrow(b),ncol(b))
plot(NA,xlim=c(0,nrow(c)),ylim=c(0,ncol(c)))
rasterImage(c,0,0,nrow(c),ncol(c))
x <- colMeans(a)
y <- colMeans(b)
z <- colMeans(c)
par(mfrow=c(1,1))
plot(x, type = "l", col="red",xlab = "Columns" , ylab = "Mean", ylim = c(0.3,1))
lines(y,col="Green")
lines(z,col="Blue")
k <- a[1:256,1:512]
l <- a[257:512,1:512]
m <- k-l
plot(NA,xlim=c(0,nrow(m)),ylim=c(0,ncol(m)))
rasterImage(abs(m),0,0,nrow(m),ncol(m))
k2 <- b[1:256,1:512]
l2 <- b[257:512,1:512]
m2 <- k2-l2
plot(NA,xlim=c(0,nrow(m2)),ylim=c(0,ncol(m2)))
rasterImage(abs(m2),0,0,nrow(m2),ncol(m2))
k3 <- c[1:256,1:512]
l3 <- c[257:512,1:512]
m3 <- k3-l3
plot(NA,xlim=c(0,nrow(m3)),ylim=c(0,ncol(m3)))
rasterImage(abs(m3),0,0,nrow(m3),ncol(m3))
library(imagine)
fivemedianfiltereda <- medianFilter(a,radius=5,times=1)
plot(NA,xlim=c(0,nrow(fivemedianfiltereda)),ylim=c(0,ncol(fivemedianfiltereda)))
rasterImage(fivemedianfiltereda,0,0,nrow(fivemedianfiltereda),ncol(fivemedianfiltereda))
fivemedianfilteredb <- medianFilter(b,radius=5,times=1)
plot(NA,xlim=c(0,nrow(fivemedianfilteredb)),ylim=c(0,ncol(fivemedianfilteredb)))
rasterImage(fivemedianfilteredb,0,0,nrow(fivemedianfilteredb),ncol(fivemedianfilteredb))
fivemedianfilteredc <- medianFilter(c,radius=5,times=1)
plot(NA,xlim=c(0,nrow(fivemedianfilteredc)),ylim=c(0,ncol(fivemedianfilteredc)))
rasterImage(fivemedianfilteredc,0,0,nrow(fivemedianfilteredc),ncol(fivemedianfilteredc))
elevenmedianfiltereda <- medianFilter(a,radius=11,times=1)
plot(NA,xlim=c(0,nrow(elevenmedianfiltereda)),ylim=c(0,ncol(elevenmedianfiltereda)))
rasterImage(elevenmedianfiltereda,0,0,nrow(elevenmedianfiltereda),ncol(elevenmedianfiltereda))
elevenmedianfilteredb <- medianFilter(b,radius=11,times=1)
plot(NA,xlim=c(0,nrow(elevenmedianfilteredb)),ylim=c(0,ncol(elevenmedianfilteredb)))
rasterImage(elevenmedianfilteredb,0,0,nrow(elevenmedianfilteredb),ncol(elevenmedianfilteredb))
elevenmedianfilteredc <- medianFilter(c,radius=11,times=1)
plot(NA,xlim=c(0,nrow(elevenmedianfilteredc)),ylim=c(0,ncol(elevenmedianfilteredc)))
rasterImage(elevenmedianfilteredc,0,0,nrow(elevenmedianfilteredc),ncol(elevenmedianfilteredc))
thirtyonemedianfiltereda <- medianFilter(a,radius=31,times=1)
plot(NA,xlim=c(0,nrow(thirtyonemedianfiltereda)),ylim=c(0,ncol(thirtyonemedianfiltereda)))
rasterImage(thirtyonemedianfiltereda,0,0,nrow(thirtyonemedianfiltereda),ncol(thirtyonemedianfiltereda))
thirtyonemedianfilteredb <- medianFilter(b,radius=31,times=1)
plot(NA,xlim=c(0,nrow(thirtyonemedianfilteredb)),ylim=c(0,ncol(thirtyonemedianfilteredb)))
rasterImage(thirtyonemedianfilteredb,0,0,nrow(thirtyonemedianfilteredb),ncol(thirtyonemedianfilteredb))
thirtyonemedianfilteredc <- medianFilter(c,radius=31,times=1)
plot(NA,xlim=c(0,nrow(thirtyonemedianfilteredc)),ylim=c(0,ncol(thirtyonemedianfilteredc)))
rasterImage(thirtyonemedianfilteredc,0,0,nrow(thirtyonemedianfilteredc),ncol(thirtyonemedianfilteredc))
Median filtering is a pre-processing tool used for removing salt and pepper noise in the image. In our project, bigger window sizes of median filter caused significant loss in signal/noise ratio. Certain color shifts looking like cracks in the table started to blend in more with the rest of the colors in the table. As we have expected before starting to median filtering, bigger window size is unreliable in median filtering. The more data you have in the window, the more you lose your reliable pixels in the image.
part2img <- readJPEG("C:/Users/ilker zeybek/Desktop/423part1grayscale.jpg", native = FALSE)
hist(part2img)
As can be seen in the histogram, it is a bell shaped curve. We assumed it is normally distributed.
sample <- sample(part2img,1000,replace = FALSE)
shapiro.test(sample)
##
## Shapiro-Wilk normality test
##
## data: sample
## W = 0.92639, p-value < 2.2e-16
P-value is sufficiently small so we conclude that our assumption about probability distribution, which was assumed normally distributed, is true.
To estimate parameters of normally distributed population, we used mean of the sample and standard deviation of the sample.(n=1000)
mean(sample)
## [1] 0.584949
sd(sample)
## [1] 0.06107764
upperlimit <- qnorm(0.999,mean(sample),sd(sample))
lowerlimit <- qnorm(0.001,mean(sample),sd(sample))
Upper limit of pixel values
upperlimit
## [1] 0.7736931
Lower limit of pixel values
lowerlimit
## [1] 0.3962049
Pixel values identified over the upperlimit
part2img[part2img > upperlimit]
## numeric(0)
Pixel values identified below the lowerlimit
part2img[part2img < lowerlimit]
## [1] 0.3960784 0.3921569 0.3686275 0.3686275 0.3725490 0.3843137
## [7] 0.3686275 0.3450980 0.3647059 0.3686275 0.3568627 0.3921569
## [13] 0.3803922 0.3882353 0.3960784 0.3803922 0.3803922 0.3607843
## [19] 0.3647059 0.3607843 0.3450980 0.3411765 0.3764706 0.3882353
## [25] 0.3607843 0.3254902 0.2941176 0.3372549 0.3568627 0.3607843
## [31] 0.3764706 0.3921569 0.3803922 0.3803922 0.3843137 0.3882353
## [37] 0.3960784 0.3921569 0.3843137 0.3843137 0.3882353 0.3803922
## [43] 0.3529412 0.3607843 0.3686275 0.3960784 0.3764706 0.3607843
## [49] 0.3960784 0.3843137 0.3764706 0.3490196 0.3215686 0.3137255
## [55] 0.3176471 0.2901961 0.3098039 0.3294118 0.3215686 0.3176471
## [61] 0.3411765 0.3764706 0.3921569 0.3960784 0.3647059 0.3333333
## [67] 0.3803922 0.3764706 0.3803922 0.3843137 0.3960784 0.3843137
## [73] 0.3725490 0.3764706 0.3803922 0.3725490 0.3607843 0.3607843
## [79] 0.3843137 0.3882353 0.3725490 0.3568627 0.3647059 0.3764706
## [85] 0.3725490 0.3882353 0.3686275 0.3490196 0.3450980 0.3568627
## [91] 0.3686275 0.3921569 0.3647059 0.3568627 0.3725490 0.3803922
## [97] 0.3450980 0.3647059 0.3686275 0.3529412 0.3921569 0.3921569
## [103] 0.3803922 0.3568627 0.3490196 0.3450980 0.3568627 0.3803922
## [109] 0.3490196 0.3450980 0.3960784 0.3764706 0.3490196 0.3568627
## [115] 0.3450980 0.3647059 0.3764706 0.3843137 0.3921569 0.3921569
## [121] 0.3843137 0.3882353 0.3843137 0.3686275 0.3921569 0.3882353
## [127] 0.3490196 0.3686275 0.3882353 0.3764706 0.3843137 0.3764706
## [133] 0.3607843 0.3568627 0.3568627 0.3568627 0.3686275 0.3686275
## [139] 0.3333333 0.3215686 0.3411765 0.3960784 0.3803922 0.3921569
## [145] 0.3960784 0.3843137 0.3764706 0.3725490 0.3725490 0.3725490
## [151] 0.3568627 0.3647059 0.3725490 0.3803922 0.3568627 0.3450980
## [157] 0.3568627 0.3607843 0.3764706 0.3843137 0.3686275 0.3764706
## [163] 0.3529412 0.3490196 0.3803922 0.3803922 0.3725490 0.3882353
## [169] 0.3843137 0.3803922 0.3921569 0.3607843 0.3607843 0.3960784
## [175] 0.3490196 0.3764706 0.3921569 0.3843137 0.3882353 0.3921569
## [181] 0.3725490 0.3725490 0.3960784 0.3843137 0.3568627 0.3450980
## [187] 0.3568627 0.3843137 0.3960784 0.3882353 0.3882353 0.3725490
## [193] 0.3882353 0.3960784 0.3450980 0.3568627 0.3725490 0.3725490
## [199] 0.3490196 0.3647059 0.3764706 0.3960784 0.3725490 0.3607843
## [205] 0.3647059 0.3843137 0.3647059 0.3254902 0.3921569 0.3725490
## [211] 0.3333333 0.3176471 0.3098039 0.2941176 0.3176471 0.3294118
## [217] 0.3137255 0.3098039 0.3254902 0.3254902 0.3254902 0.3843137
## [223] 0.3803922 0.3960784 0.3882353 0.3882353 0.3882353 0.3450980
## [229] 0.3058824 0.3450980 0.3529412 0.3607843 0.3725490 0.3725490
## [235] 0.3529412 0.3450980 0.3843137 0.3803922 0.3803922 0.3803922
## [241] 0.3686275 0.3607843 0.3686275 0.3725490 0.3647059 0.3607843
## [247] 0.3803922 0.3960784 0.3960784 0.3960784 0.3921569 0.3764706
## [253] 0.3843137 0.3843137 0.3647059 0.3803922 0.3725490 0.3607843
## [259] 0.3960784 0.3764706 0.3450980 0.3450980 0.3725490 0.3921569
## [265] 0.3843137 0.3960784 0.3882353 0.3843137 0.3882353 0.3960784
## [271] 0.3843137 0.3764706 0.3803922 0.3960784 0.3803922 0.3725490
## [277] 0.3882353 0.3882353 0.3764706 0.3607843 0.3647059 0.3843137
## [283] 0.3960784 0.3882353 0.3960784 0.3921569 0.3764706 0.3725490
## [289] 0.3764706 0.3921569 0.3882353 0.3686275 0.3647059 0.3843137
## [295] 0.3764706 0.3411765 0.3137255 0.3137255 0.3254902 0.3411765
## [301] 0.3333333 0.3490196 0.3568627 0.3607843 0.3686275 0.3725490
## [307] 0.3764706 0.3960784 0.3725490 0.3686275 0.3529412 0.3372549
## [313] 0.3333333 0.3490196 0.3764706 0.3960784 0.3764706 0.3843137
## [319] 0.3921569 0.3960784 0.3960784 0.3725490 0.3529412 0.3803922
## [325] 0.3803922 0.3882353 0.3764706 0.3725490 0.3764706 0.3843137
## [331] 0.3921569 0.3921569 0.3764706 0.3568627 0.3529412 0.3568627
## [337] 0.3647059 0.3882353 0.3568627 0.3333333 0.3411765 0.3294118
## [343] 0.3137255 0.3176471 0.3529412 0.3960784 0.3843137 0.3647059
## [349] 0.3529412 0.3607843 0.3764706 0.3803922 0.3882353 0.3647059
## [355] 0.3215686 0.3294118 0.3960784 0.3803922 0.3725490 0.3843137
## [361] 0.3960784 0.3803922 0.3803922 0.3960784 0.3882353 0.3921569
## [367] 0.3607843 0.3529412 0.3803922 0.3764706 0.3450980 0.3450980
## [373] 0.3725490 0.3960784 0.3921569 0.3921569 0.3960784 0.3607843
## [379] 0.3803922 0.3843137 0.3686275 0.3686275 0.3725490 0.3607843
## [385] 0.3372549 0.3921569 0.3960784 0.3921569 0.3882353 0.3803922
## [391] 0.3882353 0.3960784 0.3764706 0.3764706 0.3607843 0.3686275
## [397] 0.3882353 0.3764706 0.3843137 0.3921569 0.3725490 0.3921569
## [403] 0.3803922 0.3764706 0.3176471 0.3294118 0.3647059 0.3647059
## [409] 0.3490196 0.3450980 0.3490196 0.3803922 0.3960784 0.3882353
## [415] 0.3960784 0.3647059 0.3647059 0.3843137 0.3960784 0.3960784
## [421] 0.3764706 0.3882353 0.3882353 0.3725490 0.3764706 0.3882353
## [427] 0.3882353 0.3960784 0.3764706 0.3882353 0.3960784 0.3882353
## [433] 0.3882353 0.3764706 0.3921569 0.3882353 0.3882353 0.3725490
## [439] 0.3686275 0.3803922 0.3882353 0.3725490 0.3921569 0.3607843
## [445] 0.3568627 0.3607843 0.3215686 0.3019608 0.3254902 0.3411765
## [451] 0.3333333 0.3294118 0.3411765 0.3607843 0.3960784 0.3843137
## [457] 0.3803922 0.3725490 0.3764706 0.3960784 0.3882353 0.3843137
## [463] 0.3960784 0.3960784 0.3764706 0.3921569 0.3843137 0.3725490
## [469] 0.3647059 0.3843137 0.3803922 0.3490196 0.3490196 0.3490196
## [475] 0.3882353 0.3843137 0.3960784 0.3882353 0.3843137 0.3764706
## [481] 0.3725490 0.3607843 0.3725490 0.3882353 0.3960784 0.3882353
## [487] 0.3725490 0.3764706 0.3960784 0.3686275 0.3843137 0.3725490
## [493] 0.3843137 0.3921569 0.3803922 0.3960784 0.3843137 0.3921569
## [499] 0.3607843 0.3843137 0.3568627 0.3843137 0.3960784 0.3725490
## [505] 0.3803922 0.3764706 0.3764706 0.3960784 0.3882353 0.3647059
## [511] 0.3607843 0.3411765 0.3647059 0.3764706 0.3764706 0.3882353
## [517] 0.3882353 0.3764706 0.3960784 0.3960784 0.3921569 0.3921569
## [523] 0.3882353 0.3529412 0.3176471 0.3490196 0.3882353 0.3725490
## [529] 0.3960784 0.3607843 0.3686275 0.3960784 0.3843137 0.3764706
## [535] 0.3960784 0.3803922 0.3921569 0.3960784 0.3921569 0.3882353
## [541] 0.3764706 0.3058824 0.3058824 0.3333333 0.3568627 0.3607843
## [547] 0.3960784 0.3921569 0.3529412 0.3490196 0.3882353 0.3882353
## [553] 0.3882353 0.3960784 0.3686275 0.3568627 0.3411765 0.3333333
## [559] 0.3450980 0.3568627 0.3686275 0.3882353 0.3960784 0.3843137
## [565] 0.3960784 0.3882353 0.3921569 0.3725490 0.3490196 0.3411765
## [571] 0.3607843 0.3921569 0.3882353 0.3843137 0.3960784 0.3921569
## [577] 0.3686275 0.3960784 0.3686275 0.3607843 0.3921569 0.3803922
## [583] 0.3882353 0.3960784 0.3882353 0.3960784 0.3960784 0.3921569
## [589] 0.3843137 0.3882353 0.3882353 0.3607843 0.3294118 0.3333333
## [595] 0.3647059 0.3960784 0.3921569 0.3882353 0.3882353 0.3411765
## [601] 0.3921569 0.3960784 0.3803922 0.3607843 0.2823529 0.2980392
## [607] 0.3254902 0.3137255 0.3921569 0.3882353 0.3764706 0.3294118
## [613] 0.3607843 0.3921569 0.3921569 0.3803922 0.3921569 0.3490196
## [619] 0.3411765 0.3490196 0.3607843 0.3764706 0.3882353 0.3882353
## [625] 0.3882353 0.3686275 0.3843137 0.3764706 0.3803922 0.3686275
## [631] 0.3607843 0.3725490 0.3725490 0.3607843 0.3607843 0.3333333
## [637] 0.3215686 0.3137255 0.3176471 0.3607843 0.3333333 0.3372549
## [643] 0.3254902 0.3372549 0.3921569 0.3803922 0.3725490 0.3607843
## [649] 0.3647059 0.3372549 0.3333333 0.3490196 0.3607843 0.3921569
## [655] 0.3843137 0.3764706 0.3568627 0.3137255 0.3215686 0.3843137
## [661] 0.3960784 0.3647059 0.3921569 0.3607843 0.3411765 0.3176471
## [667] 0.2941176 0.3058824 0.3921569 0.3764706 0.3764706 0.3803922
## [673] 0.3882353 0.3843137 0.3882353 0.3843137 0.3882353 0.3921569
## [679] 0.3686275 0.3607843 0.3960784 0.3882353 0.3960784 0.3843137
## [685] 0.3921569 0.3803922 0.3764706 0.3686275 0.3725490 0.3764706
## [691] 0.3215686 0.3098039 0.3372549 0.3568627 0.3725490 0.3960784
## [697] 0.3686275 0.3843137 0.3803922 0.3568627 0.3333333 0.3882353
## [703] 0.3490196 0.3764706 0.3960784 0.3882353 0.3960784 0.3882353
## [709] 0.3960784 0.3803922 0.3882353 0.3843137 0.3921569 0.3921569
## [715] 0.3568627 0.3568627 0.3960784 0.3960784 0.3960784 0.3882353
## [721] 0.3960784 0.3725490 0.3921569 0.3803922 0.3803922 0.3960784
## [727] 0.3960784 0.3882353 0.3529412 0.3960784 0.3725490 0.3450980
## [733] 0.3450980 0.3294118 0.3019608 0.3176471 0.3882353 0.3882353
## [739] 0.3882353 0.3921569 0.3686275 0.3647059 0.3529412 0.3490196
## [745] 0.3607843 0.3764706 0.3725490 0.3568627 0.3372549 0.3411765
## [751] 0.3607843 0.3607843 0.3372549 0.3411765 0.3882353 0.3803922
## [757] 0.3803922 0.3764706 0.3764706 0.3921569 0.3882353 0.3725490
## [763] 0.3686275 0.3607843 0.3529412 0.3647059 0.3294118 0.3490196
## [769] 0.3921569 0.3843137 0.3490196 0.3490196 0.3607843 0.3803922
## [775] 0.3921569 0.3921569 0.3607843 0.3215686 0.3098039 0.3372549
## [781] 0.3607843 0.3490196 0.3215686 0.3411765 0.3137255 0.3019608
## [787] 0.3254902 0.3568627 0.3803922 0.3960784 0.3843137 0.3960784
## [793] 0.3843137 0.3254902 0.3568627 0.3803922 0.3568627 0.3843137
## [799] 0.3960784 0.3686275 0.3607843 0.3764706 0.3921569 0.3960784
## [805] 0.3960784 0.3843137 0.3803922 0.3529412 0.3882353 0.3725490
## [811] 0.3725490 0.3764706 0.3490196 0.3960784 0.3843137 0.3529412
## [817] 0.3803922 0.3764706 0.3921569 0.3882353 0.3647059 0.3843137
## [823] 0.3921569 0.3529412 0.3843137 0.3921569 0.3372549 0.3764706
## [829] 0.3921569 0.3882353 0.3882353 0.3843137 0.3960784 0.3882353
## [835] 0.3921569 0.3764706 0.3647059 0.3647059 0.3960784 0.3803922
## [841] 0.3686275 0.3921569 0.3960784 0.3568627 0.3803922 0.3254902
## [847] 0.3843137 0.3921569 0.3960784 0.3803922 0.3882353 0.3725490
## [853] 0.3921569 0.3647059 0.3882353 0.3960784 0.3960784 0.3921569
## [859] 0.3294118 0.3686275 0.3764706 0.3372549 0.3882353 0.3921569
## [865] 0.3960784 0.3882353 0.3843137 0.3803922 0.3921569 0.3843137
## [871] 0.3843137 0.3921569 0.3764706 0.3686275 0.3921569 0.3803922
## [877] 0.3803922 0.3725490 0.3843137 0.3960784 0.3764706 0.3921569
## [883] 0.3803922 0.3960784 0.3568627 0.3686275 0.3686275 0.3254902
## [889] 0.3568627 0.3843137 0.3882353 0.3882353 0.3843137 0.3725490
## [895] 0.3803922 0.3764706 0.3764706 0.3843137 0.3843137 0.3411765
## [901] 0.3803922 0.3921569 0.3764706 0.3764706 0.3607843 0.3333333
## [907] 0.3411765 0.3843137 0.3843137 0.3568627 0.3843137 0.3372549
## [913] 0.3058824 0.3686275 0.3411765 0.3411765 0.3137255 0.3568627
## [919] 0.3960784 0.3960784 0.3607843 0.3725490 0.3647059 0.3529412
## [925] 0.3647059 0.3843137 0.3921569 0.3843137 0.3529412 0.3803922
## [931] 0.3960784 0.3843137 0.3921569 0.3686275 0.3647059 0.3607843
## [937] 0.3647059 0.3490196 0.3529412 0.3215686 0.2784314 0.3058824
## [943] 0.3254902 0.3215686 0.3058824 0.3058824 0.3294118 0.3372549
## [949] 0.3215686 0.3176471 0.3372549 0.3411765 0.3490196 0.3686275
## [955] 0.3450980 0.3568627 0.3843137 0.3607843 0.3647059 0.3882353
## [961] 0.3921569 0.3568627 0.3764706 0.3921569 0.3921569 0.3725490
## [967] 0.3960784 0.3960784 0.3764706 0.3607843 0.3764706 0.3725490
## [973] 0.3725490 0.3960784 0.3921569 0.3921569 0.3921569 0.3411765
## [979] 0.3254902 0.3372549 0.3647059 0.3960784 0.3960784 0.3921569
## [985] 0.3725490 0.3921569 0.3960784 0.3960784 0.3843137 0.3960784
## [991] 0.3568627 0.3882353 0.3921569 0.3843137 0.3960784 0.3686275
## [997] 0.3960784 0.3921569 0.3725490 0.3921569 0.3882353 0.3803922
## [1003] 0.3843137 0.3882353 0.3764706 0.3921569 0.3921569 0.3686275
## [1009] 0.3764706 0.3568627 0.3686275 0.3960784 0.3843137 0.3647059
## [1015] 0.3882353 0.3568627 0.3411765 0.3960784 0.3843137 0.3607843
## [1021] 0.3803922 0.3882353 0.3921569 0.3764706 0.3490196 0.3568627
## [1027] 0.3764706 0.3607843 0.3843137 0.3647059 0.3372549 0.3450980
## [1033] 0.3764706 0.3921569 0.3921569 0.3647059 0.3490196 0.3647059
## [1039] 0.3568627 0.3529412 0.3764706 0.3960784 0.3803922 0.3921569
## [1045] 0.3568627 0.3529412 0.3764706 0.3960784 0.3960784 0.3882353
## [1051] 0.3882353 0.3803922 0.3725490 0.3843137 0.3803922 0.3960784
## [1057] 0.3725490 0.3803922 0.3764706 0.3725490 0.3960784 0.3764706
## [1063] 0.3960784 0.3803922 0.3411765 0.3333333 0.3568627 0.3960784
## [1069] 0.3803922 0.3960784 0.3803922 0.3686275 0.3921569 0.3882353
## [1075] 0.3960784 0.3725490 0.3843137 0.3803922 0.3568627 0.3647059
## [1081] 0.3490196 0.3254902 0.3098039 0.3333333 0.3529412 0.3607843
## [1087] 0.3764706 0.3960784 0.3686275 0.3529412 0.3882353 0.3882353
## [1093] 0.3568627 0.3294118 0.3098039 0.3294118 0.3568627 0.3450980
## [1099] 0.3215686 0.2980392 0.2980392 0.3294118 0.3764706 0.3843137
## [1105] 0.3921569 0.3882353 0.3921569 0.3686275 0.3529412 0.3490196
## [1111] 0.3607843 0.3960784 0.3686275 0.3529412 0.3882353 0.3960784
## [1117] 0.3921569 0.3921569 0.3686275 0.3725490 0.3921569 0.3725490
## [1123] 0.3843137 0.3803922 0.3882353 0.3803922 0.3960784 0.3921569
## [1129] 0.3921569 0.3960784 0.3764706 0.3294118 0.3098039 0.3686275
## [1135] 0.3843137 0.3764706 0.3882353 0.3960784 0.3960784 0.3843137
## [1141] 0.3725490 0.3882353 0.3882353 0.3725490 0.3568627 0.3529412
## [1147] 0.3647059 0.3725490 0.3882353 0.3607843 0.3450980 0.3607843
## [1153] 0.3921569 0.3803922 0.3725490 0.3960784 0.3725490 0.3607843
## [1159] 0.3725490 0.3960784 0.3960784 0.3882353 0.3921569 0.3960784
## [1165] 0.3921569 0.3607843 0.3294118 0.3490196 0.3686275 0.3686275
## [1171] 0.3490196 0.3490196 0.3686275 0.3803922 0.3843137 0.3960784
## [1177] 0.3921569 0.3960784 0.3921569 0.3921569 0.3921569 0.3725490
## [1183] 0.3882353 0.3607843 0.3529412 0.3843137 0.3803922 0.3882353
## [1189] 0.3960784 0.3960784 0.3960784 0.3725490 0.3686275 0.3843137
## [1195] 0.3882353 0.3960784 0.3921569 0.3803922 0.3921569 0.3725490
## [1201] 0.3764706 0.3607843 0.3921569 0.3921569 0.3921569 0.3843137
## [1207] 0.3686275 0.3764706 0.3843137 0.3921569 0.3960784 0.3960784
## [1213] 0.3882353 0.3921569 0.3921569 0.3921569 0.3803922 0.3882353
## [1219] 0.3882353 0.3803922 0.3803922 0.3882353 0.3960784 0.3529412
## [1225] 0.3607843 0.3843137 0.3764706 0.3725490 0.3450980 0.3764706
## [1231] 0.3882353 0.3960784 0.3803922 0.3607843 0.3764706 0.3960784
## [1237] 0.3843137 0.3921569 0.3803922 0.3686275 0.3843137 0.3960784
## [1243] 0.3921569 0.3882353 0.3882353 0.3960784 0.3843137 0.3686275
## [1249] 0.3803922 0.3960784 0.3921569 0.3764706 0.3686275 0.3921569
## [1255] 0.3568627 0.3490196 0.3921569 0.3960784 0.3764706 0.3490196
## [1261] 0.3725490 0.3960784 0.3764706 0.3607843 0.3568627 0.3607843
## [1267] 0.3960784 0.3843137 0.3921569 0.3921569 0.3725490 0.3882353
## [1273] 0.3960784 0.3764706 0.3725490 0.3764706 0.3960784 0.3960784
## [1279] 0.3882353 0.3843137 0.3843137 0.3921569 0.3960784 0.3725490
## [1285] 0.3647059 0.3647059 0.3960784 0.3882353 0.3843137 0.3882353
## [1291] 0.3921569 0.3960784 0.3921569 0.3647059 0.3764706 0.3803922
## [1297] 0.3960784 0.3960784 0.3843137 0.3803922 0.3921569 0.3764706
## [1303] 0.3803922 0.3921569 0.3843137 0.3843137 0.3882353 0.3764706
## [1309] 0.3647059 0.3882353 0.3921569 0.3960784 0.3960784 0.3960784
## [1315] 0.3686275 0.3882353 0.3803922 0.3725490 0.3882353 0.3960784
## [1321] 0.3882353 0.3921569 0.3960784 0.3921569 0.3843137 0.3686275
## [1327] 0.3725490 0.3490196 0.3647059 0.3921569 0.3921569 0.3882353
## [1333] 0.3960784 0.3568627 0.3803922 0.3960784 0.3725490 0.3725490
## [1339] 0.3333333 0.3882353 0.3921569 0.3764706 0.3725490 0.3882353
## [1345] 0.3686275 0.3882353 0.3960784 0.3960784 0.3803922 0.3843137
## [1351] 0.3921569 0.3568627 0.3764706 0.3490196 0.3803922 0.3960784
## [1357] 0.3960784 0.3921569 0.3882353 0.3960784 0.3803922 0.3686275
## [1363] 0.3960784 0.3882353 0.3960784 0.3686275 0.3450980 0.3568627
## [1369] 0.3960784 0.3686275 0.3725490 0.3843137 0.3725490 0.3529412
## [1375] 0.3333333 0.3411765 0.3843137 0.3921569 0.3921569 0.3882353
## [1381] 0.3803922 0.3803922 0.3764706 0.3764706 0.3882353 0.3960784
## [1387] 0.3843137 0.3843137 0.3960784 0.3960784 0.3921569 0.3647059
## [1393] 0.3686275 0.3803922 0.3843137 0.3960784 0.3764706 0.3647059
## [1399] 0.3843137 0.3607843 0.3294118 0.3450980 0.3647059 0.3843137
## [1405] 0.3490196 0.3058824 0.3215686 0.3294118 0.3882353 0.3921569
## [1411] 0.3921569 0.3960784 0.3921569 0.3372549 0.3725490 0.3843137
## [1417] 0.3803922 0.3843137 0.3921569 0.3921569 0.3529412 0.3686275
## [1423] 0.3843137 0.3921569 0.3960784 0.3764706 0.3490196 0.3529412
## [1429] 0.3921569 0.3725490 0.3372549 0.3058824 0.3176471 0.3568627
## [1435] 0.3843137 0.3725490 0.3764706 0.3921569 0.3960784 0.3843137
## [1441] 0.3254902 0.3254902 0.3411765 0.3725490 0.3921569 0.3843137
## [1447] 0.3960784 0.3686275 0.3647059 0.3803922 0.3803922 0.3843137
## [1453] 0.3843137 0.3843137 0.3529412 0.3333333 0.3568627 0.3960784
## [1459] 0.3803922 0.3921569 0.3882353 0.3764706 0.3764706 0.3921569
## [1465] 0.3960784 0.3686275 0.3411765 0.3725490 0.3843137 0.3803922
## [1471] 0.3843137 0.3921569 0.3803922 0.3882353 0.3882353 0.3882353
## [1477] 0.3764706 0.3960784 0.3882353 0.3960784 0.3882353 0.3529412
## [1483] 0.3921569 0.3921569 0.3960784 0.3647059 0.3882353 0.3960784
## [1489] 0.3607843 0.3764706 0.3686275 0.3803922 0.3803922 0.3921569
## [1495] 0.3568627 0.3490196 0.3843137 0.3686275 0.3490196 0.3764706
## [1501] 0.3843137 0.3529412 0.3803922 0.3882353 0.3764706 0.3921569
## [1507] 0.3529412 0.3921569 0.3803922 0.3960784 0.3882353 0.3921569
## [1513] 0.3960784 0.3921569 0.3882353 0.3960784 0.3803922 0.3843137
## [1519] 0.3960784 0.3882353 0.3686275 0.3568627 0.3803922 0.3921569
## [1525] 0.3960784 0.3725490 0.3568627 0.3882353 0.3843137 0.3882353
## [1531] 0.3960784 0.3960784 0.3921569 0.3921569 0.3960784 0.3960784
## [1537] 0.3882353 0.3490196 0.3921569 0.3803922 0.3921569 0.3843137
## [1543] 0.3843137 0.3529412 0.3647059 0.3607843 0.3921569 0.3843137
## [1549] 0.3882353 0.3960784 0.3960784 0.3725490 0.3647059 0.3960784
## [1555] 0.3960784 0.3764706 0.3764706 0.3882353 0.3882353 0.3803922
## [1561] 0.3725490 0.3764706 0.3882353 0.3960784 0.3960784 0.3764706
## [1567] 0.3764706 0.3803922 0.3921569 0.3960784 0.3960784 0.3921569
## [1573] 0.3882353 0.3843137 0.3921569 0.3921569 0.3647059 0.3647059
## [1579] 0.3686275 0.3843137 0.3686275 0.3725490 0.3921569 0.3960784
## [1585] 0.3803922 0.3725490 0.3647059 0.3764706 0.3921569 0.3764706
## [1591] 0.3882353 0.3882353 0.3882353 0.3921569 0.3725490 0.3294118
## [1597] 0.3254902 0.3294118 0.3450980 0.3843137 0.3725490 0.3725490
## [1603] 0.3450980 0.3490196 0.3843137 0.3960784 0.3725490 0.3960784
## [1609] 0.3843137 0.3921569 0.3607843 0.3450980 0.3803922 0.3882353
## [1615] 0.3725490 0.3647059 0.3568627 0.3764706 0.3882353 0.3843137
## [1621] 0.3960784 0.3960784 0.3803922 0.3960784 0.3882353 0.3607843
## [1627] 0.3764706 0.3960784 0.3921569 0.3960784 0.3843137 0.3882353
## [1633] 0.3843137 0.3960784 0.3921569 0.3607843 0.3568627 0.3686275
## [1639] 0.3686275 0.3882353 0.3725490 0.3647059 0.3843137 0.3490196
## [1645] 0.3882353 0.3882353 0.3647059 0.3647059 0.3882353 0.3960784
## [1651] 0.3725490 0.3843137 0.3960784 0.3921569 0.3725490 0.3686275
## [1657] 0.3960784 0.3843137 0.3764706 0.3529412 0.3490196 0.3254902
## [1663] 0.3450980 0.3882353 0.3960784 0.3764706 0.3725490 0.3686275
## [1669] 0.3725490 0.3843137 0.3725490 0.3294118 0.3411765 0.3529412
## [1675] 0.3411765 0.3490196 0.3568627 0.3372549 0.3254902 0.3647059
## [1681] 0.3921569 0.3843137 0.3882353 0.3882353 0.3764706 0.3686275
## [1687] 0.3647059 0.3333333 0.3098039 0.3450980 0.3803922 0.3882353
## [1693] 0.3803922 0.3803922 0.3882353 0.3803922 0.3725490 0.3607843
## [1699] 0.3529412 0.3725490 0.3607843 0.3529412 0.3921569 0.3921569
## [1705] 0.3960784 0.3568627 0.3686275 0.3764706 0.3921569 0.3647059
## [1711] 0.3647059 0.3764706 0.3411765 0.3647059 0.3568627 0.3215686
## [1717] 0.3607843 0.3607843 0.3960784 0.3921569 0.3411765 0.3294118
## [1723] 0.3333333 0.3372549 0.3254902 0.3254902 0.3764706 0.3607843
## [1729] 0.3764706 0.3764706 0.3921569 0.3882353 0.3764706 0.3254902
## [1735] 0.3450980 0.3921569 0.3960784 0.3843137 0.3960784 0.3960784
## [1741] 0.3882353 0.3921569 0.3882353 0.3882353 0.3843137 0.3803922
## [1747] 0.3764706 0.3450980 0.3647059 0.3960784 0.3764706 0.3843137
## [1753] 0.3764706 0.3607843 0.3607843 0.3725490 0.3921569 0.3411765
## [1759] 0.3215686 0.3607843 0.3843137 0.3568627 0.3450980 0.3372549
## [1765] 0.3411765 0.3686275 0.3764706 0.3843137 0.3843137 0.3882353
## [1771] 0.3882353 0.3647059 0.3725490 0.3647059 0.3215686 0.3176471
## [1777] 0.3529412 0.3803922 0.3921569 0.3960784 0.3843137 0.3803922
## [1783] 0.3803922 0.3882353 0.3725490 0.3882353 0.3921569 0.3960784
## [1789] 0.3803922 0.3921569 0.3882353 0.3843137 0.3960784 0.3882353
## [1795] 0.3882353 0.3960784 0.3882353 0.3686275 0.3921569 0.3450980
## [1801] 0.3647059 0.3882353 0.3843137 0.3921569 0.3960784 0.3882353
## [1807] 0.3803922 0.3882353 0.3803922 0.3921569 0.3921569 0.3843137
## [1813] 0.3921569 0.3882353 0.3686275 0.3960784 0.3686275 0.3607843
## [1819] 0.3725490 0.3882353 0.3803922 0.3803922 0.3960784 0.3882353
## [1825] 0.3921569 0.3607843 0.3529412 0.3450980 0.3686275 0.3843137
## [1831] 0.3803922 0.3960784 0.3921569 0.3960784 0.3764706 0.3568627
## [1837] 0.3529412 0.3921569 0.3882353 0.3882353 0.3882353 0.3529412
## [1843] 0.3647059 0.3843137 0.3882353 0.3686275 0.3921569 0.3921569
## [1849] 0.3882353 0.3647059 0.3647059 0.3921569 0.3803922 0.3686275
## [1855] 0.3725490 0.3686275 0.3843137 0.3960784
Changing the out-of-limit pixel values to 0 (black).
part2img[part2img > upperlimit] <- 0
part2img[part2img < lowerlimit] <- 0
Display of the new image and the original image in a plot.
part2img2 <- readJPEG("C:/Users/ilker zeybek/Desktop/423part1grayscale.jpg", native = FALSE)
plot(NA,xlim=c(0,nrow(part2img)),ylim=c(0,ncol(part2img)))
rasterImage(part2img,0,0,nrow(part2img),ncol(part2img))
plot(NA,xlim=c(0,nrow(part2img2)),ylim=c(0,ncol(part2img2)))
rasterImage(part2img2,0,0,nrow(part2img2),ncol(part2img2))
Since our image is grayscale, we have expected that our image has more pixel values below the lower limit than pixel values over the upper limit. It is clearly shown that it has significantly more pixel values below lower limit since there is not any pixel value over the upper limit. Pixel values lower than the lower limit is on the darker colored part of the original grayscale image of table because their pixel values are closer to 0 than brighter colored parts of the table. Only explanation that we do not have any pixel values over the upper limit is image of the table is grayscale that doesn’t has any colored parts like in the original image used in part 1.
fracturepic <- part2img2
for (i in 1:10){
for(j in 1:10){
fiftyonepatch <- fracturepic[(51*(i-1)+1):(51*i),(51*(j-1)+1):(51*j)]
meanpatch <- mean(fiftyonepatch)
stdpatch <- sd(fiftyonepatch)
patchupperlimit <- qnorm(0.999,meanpatch,stdpatch)
patchlowerlimit <- qnorm(0.001,meanpatch,stdpatch)
fracturepic[(51*(i-1)+1):(51*i),(51*(j-1)+1):(51*j)] <- ifelse(fracturepic[(51*(i-1)+1):(51*i),(51*(j-1)+1):(51*j)] < patchlowerlimit,0,fracturepic[(51*(i-1)+1):(51*i),(51*(j-1)+1):(51*j)])
fracturepic[(51*(i-1)+1):(51*i),(51*(j-1)+1):(51*j)] <- ifelse(fracturepic[(51*(i-1)+1):(51*i),(51*(j-1)+1):(51*j)] > patchupperlimit,0,fracturepic[(51*(i-1)+1):(51*i),(51*(j-1)+1):(51*j)])}}
Display of 51x51 patched and Original Image in a single plot
par(mfrow=c(1,2))
plot(NA,xlim=c(0,nrow(fracturepic)),ylim=c(0,ncol(fracturepic)),xlab="Horizontal",ylab="Vertical")
rasterImage(fracturepic,0,0,nrow(fracturepic),ncol(fracturepic))
plot(NA,xlim=c(0,nrow(part2img)),ylim=c(0,ncol(part2img)),xlab="Horizontal",ylab="Vertical")
rasterImage(part2img2,0,0,nrow(part2img2),ncol(part2img2))
We expected more black pixels since we have treated our original grayscale image like 100 different 51x51 sized pictures. Each window has less population size and its own boundary limits. This caused more black pixels in the patched image.